package com.example.tests;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Film {
	private WebDriver driver;
	private String baseUrl;
	private StringBuffer verificationErrors = new StringBuffer();
	@Before
	public void setUp() throws Exception {
		driver = new FirefoxDriver();
		baseUrl = "http://localhost/";
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	}

	@Test
	public void testUntitled3() throws Exception {
		driver.get(baseUrl + "/php4dvd/");
		driver.findElement(By.id("username")).clear();
		driver.findElement(By.id("username")).sendKeys("admin");
		driver.findElement(By.name("password")).clear();
		driver.findElement(By.name("password")).sendKeys("admin");
		driver.findElement(By.name("submit")).click();
		driver.findElement(By.cssSelector("img[alt=\"Add movie\"]")).click();
		driver.findElement(By.name("imdbid")).clear();
		driver.findElement(By.name("imdbid")).sendKeys("1");
		driver.findElement(By.name("name")).clear();
		driver.findElement(By.name("name")).sendKeys("Red and Black");
		driver.findElement(By.name("aka")).clear();
		driver.findElement(By.name("aka")).sendKeys("Red and Black");
		driver.findElement(By.name("year")).clear();
		driver.findElement(By.name("year")).sendKeys("1987");
		driver.findElement(By.name("duration")).clear();
		driver.findElement(By.name("duration")).sendKeys("121");
		driver.findElement(By.name("rating")).clear();
		driver.findElement(By.name("rating")).sendKeys("9");
		driver.findElement(By.id("loaned_yes")).click();
		driver.findElement(By.name("loanname")).clear();
		driver.findElement(By.name("loanname")).sendKeys("2012-12-15");
		driver.findElement(By.name("notes")).clear();
		driver.findElement(By.name("notes")).sendKeys("1");
		driver.findElement(By.name("taglines")).clear();
		driver.findElement(By.name("taglines")).sendKeys("1");
		driver.findElement(By.name("plotoutline")).clear();
		driver.findElement(By.name("plotoutline")).sendKeys("1");
		driver.findElement(By.name("plots")).clear();
		driver.findElement(By.name("plots")).sendKeys("1");
		driver.findElement(By.id("text_languages_0")).clear();
		driver.findElement(By.id("text_languages_0")).sendKeys("1");
		driver.findElement(By.name("subtitles")).clear();
		driver.findElement(By.name("subtitles")).sendKeys("1");
		driver.findElement(By.name("audio")).clear();
		driver.findElement(By.name("audio")).sendKeys("1");
		driver.findElement(By.name("video")).clear();
		driver.findElement(By.name("video")).sendKeys("1");
		driver.findElement(By.name("country")).clear();
		driver.findElement(By.name("country")).sendKeys("1");
		driver.findElement(By.name("genres")).clear();
		driver.findElement(By.name("genres")).sendKeys("1");
		driver.findElement(By.name("director")).clear();
		driver.findElement(By.name("director")).sendKeys("1");
		driver.findElement(By.name("writer")).clear();
		driver.findElement(By.name("writer")).sendKeys("1");
		driver.findElement(By.name("producer")).clear();
		driver.findElement(By.name("producer")).sendKeys("1");
		driver.findElement(By.name("music")).clear();
		driver.findElement(By.name("music")).sendKeys("1");
		driver.findElement(By.name("cast")).clear();
		driver.findElement(By.name("cast")).sendKeys("1");
		driver.findElement(By.id("submit")).click();
		driver.findElement(By.cssSelector("img[alt=\"Remove\"]")).click();
		// ERROR: Caught exception [ERROR: Unsupported command [getConfirmation]]
		driver.switchTo().alert().accept();
		driver.findElement(By.linkText("Log out")).click();
		// ERROR: Caught exception [ERROR: Unsupported command [getConfirmation]]
		driver.switchTo().alert().accept();
	}

	@After
	public void tearDown() throws Exception {
		driver.quit();
		String verificationErrorString = verificationErrors.toString();
		if (!"".equals(verificationErrorString)) {
			fail(verificationErrorString);
		}
	}

	private boolean isElementPresent(By by) {
		try {
			driver.findElement(by);
			return true;
		} catch (NoSuchElementException e) {
			return false;
		}
	}
}
